<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Search!</title>
<style type="text/css">
.clearfix:after {
	content: ".";
	display: block;
	height: 0;
	clear: both;
	visibility: hidden;
}

body {
	background-color: #333;
	margin: 0;
	padding: 0;
	font-size: 14px;
}

#wrapper {
	width: 800px;
	margin: 0 auto;
}

#mainbox {
	background-color: #F3EFED;
	border-radius: 0 0 8px 8px;
	position: relative;
}

#mainbox:after {
	content: " ";
	position: absolute;
	left: -6px;
	top: -1px;
	width: 810px;
	height: 190px;
	z-index: -1;
	border-radius: 0 0 10px 10px;
	background-color: rgba(255, 255, 255, 0.5);
	border: 1px solid white;
	opacity: 0.3;
}

#header {
	font-size: 5em;
	font-family: Helvetica, Arial, sans-serif;
	font-weight: bold;
	color: #3E3E3E;
	text-shadow: 2px 2px 1px white;
	text-align: center;
	padding-top: 0.3em;
	padding-bottom: 0.2em;
}

#search-form {
	padding-bottom: 20px;
}

form {
	margin: 0px 20px;
}

form input {
	font-size: 2em;
	padding: 4px;
	width: 600px;
	float: left;
}

form button {
	font-size: 2em;
	padding: 6px;
	width: 120px;
	margin-left: 22px;
	color: green;
	font-weight: bold;
}

#results {
	background-color: #C6BFB9;
	border-radius: 0 0 8px 8px;
	border: 1px solid #ccc;
	padding: 0;
	margin-top: 0;
	width: 608px;
	margin-left: 20px;
	border-top: none;
}

#results .shadow {
	width: 100%;
	display: block;
	box-shadow: 0 3px 6px black;
	height: 1px;
	margin-top: -2px;
}

#results li {
	list-style: none;
	margin: 0;
	padding: 4px 20px;
	border-top: 1px solid rgba(255, 255, 255, 0.4);
	border-bottom: 1px solid rgba(100, 100, 100, 0.4);
	height: 2em;
	font-size: 1.5em;
	overflow: none;
	font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
	-webkit-transition: all 0.5s;
}

#results li:hover {
	background-color: rgba(255, 255, 255, 0.5);
}

#results li:last-child {
	border-radius: 0 0 8px 8px;
	border-bottom: none;
}

#results li .document-link {
	float: left;
	line-height: 2em;
	color: #3e3e4F;
}

#results li .document-link:hover {
	color: black;
}

#results li .document-rating {
	float: right;
	line-height: 2em;
	font-weight: bold;
	text-shadow: 1px 1px 1px #eee;
}
</style>
<script id="result" type="text/html">
<li>
	<a href="{{ url }}" class="document-link">{{ title }}</a>
	<div class="document-rating">{{ rating }}</div>
</li>
</script>
</head>
<body>
	<div id="wrapper">
        <div id="mainbox">
            <div id="header">Search!</div>
            <div id="search-form">
                <form>
                    <!--<input type="hidden" name="debug" value="1" />-->
                    <input type="text" name="q" id="q" value="" placeholder="Search" />
                    <button type="submit" name="search" id="search">Go!</button>
                </form>
            </div>
        </div>
        <ul id="results">
        	<div class="shadow"></div>
        </ul>
		
		
	</div>

    <!-- Javascript -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
    <script src="https://github.com/andyet/ICanHaz.js/raw/master/ICanHaz.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    var searchUrl = window.location.pathname + '?q=';
    
   	$("#search").bind('click', function() {
   		var query = $("#q").attr('value');
   		console.log("Query for : " + query);
   		
   		$.getJSON(searchUrl + encodeURIComponent(query), function(data) {
   			if(data.status === 'error') {
   				console.error('Server error retrieiving search results');
   				console.log(data);
   				return;
   			}
   			console.log('SUCCESS:');
   			console.log(data);
   			loadTemplate(data);
   		})
   		.error(function() {
   			console.log('Error retrieving search results.');
   		});
   		
   		return false;
   	});
   	
   	var loadTemplate = function(data) {   		
   		var resultsEl = $('#results');
   		resultsEl.children('li').remove();
   		resultsEl.slideUp();
   		
   		data.results.forEach(function(result) {
   			console.log(result);
   			
  			resultsEl.append(ich.result({
  				doc_id: result.doc_id,
  				title: result.title,
  				rating: result.rating,
  				url: window.location.pathname + '?document=' + result.doc_id
  			}));
   				
   		});
   		
   		resultsEl.slideDown('fast');
   		
   	};
   	
    </script>
</body>
</html>

